package com.oriole.api.config;

import liquibase.integration.spring.SpringLiquibase;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author doublelife
 * @Email: hautxxxyzjk@163.com
 * @DateTime: 2020/7/5 21:55
 * description:
 */
@Configuration
public class LiquibaseConfig {

    @Value("${spring.liquibase.enabled}")
    private Boolean enable;

    @Value("${spring.liquibase.change-log}")
    private String changeLog;

    @Value("${spring.liquibase.drop-first}")
    private Boolean dropFirst;

    @Value("${spring.liquibase.contexts}")
    private String contexts;

    @Bean
    public SpringLiquibase liquibase(@Qualifier("dataSource") DataSource dataSource) {
        SpringLiquibase liquibase = new SpringLiquibase();
        liquibase.setDataSource(dataSource);
        liquibase.setShouldRun(enable);
        liquibase.setChangeLog(changeLog);
        liquibase.setDropFirst(dropFirst);
        liquibase.setContexts(contexts);
        return liquibase;
    }

}
